package com.brainshare.common.enums;

import com.brainshare.common.constant.NumberConstants;

import java.util.ArrayList;
import java.util.List;

/**
 * 提现卡类型枚举
 * @author wll
 */
public enum WithdrawalCardTypeEnum {
    FILL_BASE_INFO(10,0,20,30,"填写基础信息"),
    DO_EXERCISES_1(11,1,30,50,"第一组题完成"),
    DO_EXERCISES_2(12,1,10,30,"第二组题完成"),
    ADD_ENTERPRISE_WECHAT(13,0,10,30,"添加企业微信");

    //编码
    private final Integer code;
    //提现卡类型(1:金卡 0:银卡)
    private final Integer cardType;
    //最小金额
    private final Integer minAmount;
    //最大金额
    private final Integer maxAmount;
    //描述
    private final String info;

    WithdrawalCardTypeEnum(Integer code,Integer cardType,Integer minAmount,Integer maxAmount, String info)
    {
        this.code = code;
        this.cardType = cardType;
        this.minAmount = minAmount;
        this.maxAmount = maxAmount;
        this.info = info;
    }

    public Integer getCode()
    {
        return code;
    }

    public Integer getCardType() {
        return cardType;
    }

    public Integer getMinAmount() {
        return minAmount;
    }

    public Integer getMaxAmount() {
        return maxAmount;
    }

    public String getInfo()
    {
        return info;
    }

    public static boolean checkWithdrawalType(int withdrawalType)
    {
        List<Integer> withdrawalCodeList = getWithdrawalCodeList();
        return withdrawalCodeList.contains(withdrawalType);
    }

    public static List<Integer> getWithdrawalCodeList(){
        List<Integer>  withdrawalCodeList= new ArrayList<>();
        for (WithdrawalCardTypeEnum withdrawalCardTypeEnum : WithdrawalCardTypeEnum.values()) {
            withdrawalCodeList.add(withdrawalCardTypeEnum.getCode());
        }
        return withdrawalCodeList;
    }


    public static Integer getAmountByCode(Integer code,Long userId)
    {
        if (null==code){
            return null;
        }

        for (WithdrawalCardTypeEnum withdrawalCardTypeEnum : WithdrawalCardTypeEnum.values()) {

            if (code==withdrawalCardTypeEnum.getCode()){
                if (code==DO_EXERCISES_2.code && userId % NumberConstants.TEN_THOUSAND==0){
                    return NumberConstants.FOUR_HUNDRED_AND_EIGHTY;
                }

                Integer minAmount = withdrawalCardTypeEnum.getMinAmount();
                Integer maxAmount = withdrawalCardTypeEnum.getMaxAmount();

                int randomResult = (int) (minAmount + Math.random() * (maxAmount - minAmount + 1));
                return randomResult;
            }
        }
        return null;
    }

    public static Integer getCartTypeByCode(Integer code)
    {
        if (null==code){
            return null;
        }
        for (WithdrawalCardTypeEnum withdrawalCardTypeEnum : WithdrawalCardTypeEnum.values()) {
            if (code==withdrawalCardTypeEnum.getCode()){ ;
                return withdrawalCardTypeEnum.getCardType();
            }
        }
        return null;
    }
}
